package com.sky.controller.user;

import com.sky.dto.ReplyDTO;
import com.sky.result.Result;
import com.sky.service.ReplyService;
import com.sky.vo.ReplyVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/reply")
@Tag(name = "回复相关接口")
public class ReplyController {

    private final ReplyService replyService;

    @Autowired
    public ReplyController(ReplyService replyService) {
        this.replyService = replyService;
    }

    /**
     * 新增回复
     */
    @PostMapping("/add")
    @Operation(summary = "新增回复")
    public Result add(@RequestBody ReplyDTO replyDTO) {
        log.info("新增回复");
        replyService.addReply(replyDTO);
        return Result.success();
    }

    /**
     * 根据评论id查询所有回复
     */
    @GetMapping("/list")
    @Operation(summary = "根据评论id查询所有回复")
    public Result<List<ReplyVO>> list(Long commentId) {
        log.info("根据评论id查询所有回复");
        List<ReplyVO> list = replyService.listReply(commentId);
        return Result.success(list);
    }


}
